package com.monkey.core.domain.role;

import com.monkey.core.domain.permission.Permission;
import com.monkey.core.domain.resource.Menu;
import com.monkey.core.repository.BaseRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Set;

/**
 * Created by silentwu on 2015/8/4.
 */
public interface RoleResourcePermissionRepository extends BaseRepository<RoleResourcePermission, Long> {

    @Query("from RoleResourcePermission r where r.role.role = ?1")
    Set<RoleResourcePermission> findByRoleString(String roleString);

    void deleteByRoleAndMenuAndPermission(Role role, Menu menu, Permission permission);

    List<RoleResourcePermission> findByRoleAndMenu(Role role, Menu menu);

    Page<RoleResourcePermission> findByRole(Role role, Pageable pageable);

    List<RoleResourcePermission> findByRole(Role role);
}
